package cn.edu.bcu.ls.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.edu.bcu.ls.entity.Course;
import cn.edu.bcu.ls.entity.Section;
import cn.edu.bcu.ls.entity.SectionParams;
import cn.edu.bcu.ls.entity.Tag;
import cn.edu.bcu.ls.entity.User;
import cn.edu.bcu.ls.serviceImpl.CourseService;
import cn.edu.bcu.ls.serviceImpl.TagoutService;
import io.swagger.annotations.ApiOperation;

@RestController
public class CourseController {
	@Autowired
	private CourseService courseService;
	
	@Autowired
	private TagoutService tagoutService;

	/**
	 * 增加课程
	 * @param course
	 * @return
	 */
	@ApiOperation(value = "添加课程，传入你想要的传的值就行")
	@PostMapping(value="Course")
	public boolean insertCourse(Course course) {
		if (courseService.insert(course) >0) {
			return true;
		}else {
			return false;
		}
	}
	
	 @ApiOperation(value = "删除课程，传入id")
	 @DeleteMapping(value="Course/{c_id}")
	 public boolean deleteUser(@PathVariable("c_id") Integer c_id) {
		 if (courseService.deleteByPrimaryKey(c_id) >0) {
				return true;
			}else {
				return false;
			}
	 }
	 
	 @ApiOperation(value="修改课程信息，传入id和想修改的值")
	 @PutMapping(value="Course")
	 public boolean updateUser(Course course) {
		 if (courseService.updateByPrimaryKeySelective(course) >0) {
				return true;
			}else {
				return false;
			}
	 }
	
	@ApiOperation(value="查看单个课程_传入id")
	@GetMapping(value="Course/{c_id}")
	public Course queryUser(@PathVariable("c_id") Integer c_id) {
		return courseService.selectByPrimaryKey(c_id);
		
	}
	
	@ApiOperation(value="根据tag或课程名模糊搜索课程")
	@GetMapping(value="Course/searchCourse/{context}")
	public List<Course> queryLikeContext(@PathVariable("context") String context) {
		return courseService.queryLikeContext(context);
		
	}

	@GetMapping(value="Course")
	public List<Course> queryCourses(){
		return courseService.queryCourse();

}
	
	@GetMapping(value = "CourseByTag")
	public List<Tag> getTagByCourseId(){
		return tagoutService.getTagByCourseId();
	}
	
	
}